import type { ActionType, ProColumns, ProDescriptionsItemProps } from '@ant-design/pro-components';
import {
    FooterToolbar,
    PageContainer,
    ProDescriptions,
    ProTable,
} from '@ant-design/pro-components';
import '@umijs/max';
import { Button, Drawer, message, Space, Tooltip } from 'antd';
import React, { useRef, useState } from 'react';
import {
    deleteInterfaceInfoUsingPost,
} from '@/services/api-share-backhend/interfaceInfoController';
import { SortOrder } from 'antd/lib/table/interface';
import {getUserInterfaceInfoByUserIdUsingGet} from "@/services/api-share-backhend/userInterfaceInfoController";
import {history} from "@umijs/max";

/**
 * @en-US Add node
 * @zh-CN 添加节点
 * @param fields
 */



const OwnInterface: React.FC = () => {
    /**
     * @en-US Pop-up window of new window
     * @zh-CN 新建窗口的弹窗
     *  */
    /**
     * @en-US The pop-up window of the distribution update window
     * @zh-CN 分布更新窗口的弹窗
     * */
    const actionRef = useRef<ActionType>();


    /**
     *  Delete node
     * @zh-CN 删除节点
     *
     * @param selectedRows
     */

    const columns: ProColumns<API.UserInterfaceInfoVO>[] = [
        {
            title: 'id',
            dataIndex: 'id',
            valueType: 'index',
        },
        {
            title: '接口名称',
            dataIndex: 'name',
            valueType: 'text',
            ellipsis: true,
            render: (text, record) => (
                // `title` 是在鼠标悬浮时显示的内容
                <Tooltip title={record.name}>
                    <div>
                        {/*正常表格显示的内容*/}
                        {text}
                    </div>
                </Tooltip>
            ),
        },

        {
            title: '剩余次数',
            dataIndex: 'leftNum',
            valueType: 'text',
            hideInSearch:true

        },
        {
            title: '总分配次数',
            dataIndex: 'totalNum',
            valueType: 'text',
            hideInSearch:true

        },
        {
            title: '接口状态',
            dataIndex: 'status',
            hideInSearch:true,
            width: 50,
            valueEnum: {
                0: {
                    text: '关闭',
                    status: 'Default',
                },
                1: {
                    text: '开启',
                    status: 'Processing',
                },
            },
        },
        {
            title: '操作',
            dataIndex: 'option',
            valueType: 'option',
            render: (_, record) => (
                <Space direction="vertical">

                    <Button
                        key={'view'}
                        type={"primary"}
                        onClick={() => {
                            console.log(record)
                            const url=`/show_interface_detail/${record.id}`
                            history.push(url)
                        }}
                    >
                        查看接口
                    </Button>
                </Space>
            ),
        },
    ];
    return (
        <PageContainer>
            <ProTable<API.UserInterfaceInfoVO, API.PageParams>
                actionRef={actionRef}
                rowKey="id"
                search={{
                    labelWidth: 120,
                    style: {height:10,paddingTop:0}
                }}
                request={
                    async (
                        params,
                        sort: Record<string, SortOrder>,
                        filter: Record<string, (string | number)[] | null>,
                    ) => {
                        const res
                            = await getUserInterfaceInfoByUserIdUsingGet({...params});

                        if (res?.data) {
                            const ans = {
                                data: res.data,
                                success: true,
                                total: res.data.length,
                            };
                            return ans;
                        } else {
                            const ans = {
                                data: null,
                                success: false,
                                total: 0,
                            };
                            return ans;
                        }
                    } //请求数据
                }
                columns={columns}
            />
        </PageContainer>
    );
};
export default OwnInterface;
